package cn.edu.jlu.grid.vjm;

import java.net.Socket;
import java.util.Collection;
import java.util.Vector;

public class VJobAvailableMessage extends VJMMessage {
	private String gkContact;
	private int reservationHandler;
	private int requestId;
	private int vjobId;
	
	public VJobAvailableMessage() {}
	
	public void onSend() {
		VJobExecute ve = VJobExecute.getInstance();
		gkContact = ve.getGKContact();
		reservationHandler = ve.getReservationHandler();
		requestId = ve.getRequestId();
		vjobId = ve.getVjobId();
	}
	public void onReceive(Socket connection) {
		VJobPool.getInstance().setVJobGKContact(reservationHandler, requestId, vjobId, gkContact);
		Collection<VJMPIJob> mpiJobs = VJMCenter.getInstance().getRegisteredMPIJobs();
		for(VJMPIJob job : mpiJobs) {
			if(job.getResourceHandler() == reservationHandler) {
				job.notifyAvailable();
			}
		}
	}
	public String toString() {
		return "VJobAvailableMessage: reservationId: " + reservationHandler +
			" requestId: " + requestId + " vjobId:" + vjobId +
			" gkContact: " + gkContact;
	}
}
